Component({
  /**
   * 组件的属性列表
   */
  properties: {
    assign: {
      type: Boolean,
      value: true
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    list: [
      {
        icon: '/assets/main/toilet.png',
        text: '清洗厕所马桶',
        dropdown: false
      },
      {
        icon: '/assets/main/clean2.png',
        text: '打扫厕所下水道',
        dropdown: false
      },
      {
        icon: '/assets/main/trash.png',
        text: '扔垃圾',
        dropdown: false
      }
    ],
    userinfo: {
      dormitory: '',
      date: ''
    }
  },
  lifetimes: {
    attached() {
      this.getTodayDate();
    }
  },
  pageLifetimes: {
    show() {
      this.getTodayDate();
      this.getUserInfo();
      this.getAssignments();
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getTodayDate() {
      const date = new Date();
      const year = date.getFullYear();
      const month = date.getMonth() + 1;
      const day = date.getDate();
      const formattedDate = `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
      this.setData({
        'userinfo.date': formattedDate
      });
    },
    getUserInfo(){
      wx.request({
        url: 'http://127.0.0.1:4523/m1/6449731-6148418-default/user/info',
        method: 'GET',
        header: {
          'Content-Type': 'application/json' 
        },
        success:(res)=> {
          console.log(res)
          this.setData({
            'userinfo.dormitory': res.data.dormitory
          })
        },
        fail: (err) => {
          console.error('报错:',err);
        }
      })
    },
    getAssignments(){
      wx.request({
        url: 'http://127.0.0.1:4523/m1/6449731-6148418-default/schedule/assign',
        method: 'GET',
        header: {
          'Content-Type': 'application/json' 
        },
        success:(res)=>{
          console.log('卫生情况',res)
        },
        fail: (err) => {
          console.error('报错:',err);
        }
      })
    },
    goAssign(){
      this.triggerEvent('changeAssign', { assign: false });
    }
  }
})